package com.zxm.ssm.mapper;

import com.zxm.ssm.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author ZXM
 * @ClassName UserMapper
 * @Description TODO
 * @date 2021/7/18 10:19
 */
@Mapper
public interface UserMapper {
    @Select("select * from user where username=#{username} and password= #{password}")
    User selectUserByIdAndPwd(@Param(value = "username") String username, @Param(value = "password") String password);

    @Insert("insert into user values(default, #{username}, #{password}, #{money}, #{gender}, #{age}, #{phone}, #{createTime}, #{role})")
    Integer addUser(User user);

    @Select("select * from user")
    List<User> findAll();

    @Insert("insert into user values(default, #{username}, #{password}, #{money}, #{gender}, #{age}, #{phone}, #{createTime},  #{role})")
    Integer save(User user);

    @Select("select * from user where id=#{id}")
    User findById(int id);

    @Update("update user set username=#{username}, password=#{password}, money=#{money}, gender=#{gender}, age=#{age}, phone=#{phone}, createTime=#{createTime}, role=#{role} where id=#{id}")
    Integer update(User user);

    @Delete("delete from user where id=#{id}")
    void delById(int id);
}
